<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="{$keywords}" />
<meta name="Description" content="{$description}" />
<title>{$page_title}</title>
</head>
{insert_scripts files='jquery.js'}
<link href="./styles/ware.css" rel="stylesheet" type="text/css" />
<body  style="margin:10px;">
<div id="heard">
  <span class="left">添加出货单</span>
    <span class="flie_box">
      <form action="warehouse.php?act=add_out" enctype="multipart/form-data" method="post" name="uploadfile">
      <input type="hidden" name="step" value="inport_goods">
      <input name="file" type="file" size="40"  class="file">
      <input type="submit" />
      </form>
  </span>
  <span class="right">输入商品编号或者名字<input type="text" name="keyword"  id="keyword" onkeydown="key_down(event);"/> <input type="button" onclick="add_goods();" value="添加" /></span>
</div>
<form action="warehouse.php?act=add_out&step=complete" id="complete" method="post" onsubmit="return form_submit();">
<div class="right" id="purchase_remarks">
  <select name="out_code"><option value='0'>出货原由</option>
        <option value="1">报损</option>
        <option value="2">调配</option>
        <option value="3">线下订单</option>
        <option value="4">补发</option>
    </select>
    选择地区    <select name="area_id"><option value='0'>全部</option>
    {foreach from=$agency_list item=agency}
        <option value="{$agency.agency_id}" {if $agency.agency_id eq $admin_info.agency_id}selected{/if}>{$agency.agency_name}</option>
    {/foreach}
    </select>
  出货单备注 <input type="text"  name="note"/> <input type="button" onclick="$('#complete').submit();" value="完成出货单">
</div>

<div id="goods_list">
<table width="100%" cellpadding="2" cellspacing="0">
  <tbody>
  <tr class="th">
    <th>商品名称[商品属性]</th>
    <th>当前地区</th>
    <th>商品编号</th>
    <th>原库存</th>
    <th>出库数量</th>
    <th>出库价格</th>
    <th>操作</th>
  </tr>
  {foreach from=$goods_list item=goods}
  <tr class="td">
    <input type="hidden" name="goods_id[]" value="{$goods.goods_id}">
    <input type="hidden" name="goods_attr_id[]" value="{$goods.goods_attr_id}">
    <input type="hidden" name="goods_name[]" value="{$goods.goods_name}">
    <input type="hidden" name="goods_attr_name[]" value="{$goods.attr_value}">
    <input type="hidden" name="goods_sku[]" value="{$goods.goods_sku}">
    <td width="180">{$goods.goods_name}{if $goods.attr_value}【{$goods.attr_value}】{/if}</td>
    <td width="180">{$goods.area_name}</td>
    <td width="100">{$goods.goods_sku}</td>
    <td><input type="text" name="goods_number[]" class="goods_number" value="{$goods.goods_number}" style="width:100px;"/></td>
    <td><input type="text" name="goods_price[]" value="{$goods.goods_price}" style="width:100px;"/></td>
    <td onclick="$(this).parents('.td').remove();">删除</td>
  </tr>
  {/foreach}
  </tbody>
</table>
</div>
</form>



</body>
<script>
function add_goods(){
  var keyword=$('#keyword').val();
  var a=Math.random()*10;
  var area_id=$("select:[name='area_id'] ").val();
  if(area_id == 0){
    alert('请选择地区');
    return false;
  }
  var url="warehouse.php?act=add_out&step=obtain_goods&area_id="+area_id+"a="+a;
  htmlobj= $.post(url, {'keyword' : keyword }, function(data){
  add_goods_return(data);
  },'JSON');
}
function key_down(event){
  if(event.which==13){
    add_goods();
  }
}
function add_goods_return(data){
  $('#goods_list').after(data);
}
function select_goods(){
  $('.obtain_goods').find('.td').each(function(){
     var goods_number = $(this).find('.goods_number').val();
     if (goods_number>0) {
      $("#goods_list").find(".th").after($(this));

     };
  });
  $("#obtain_goods").remove();
}
function form_submit(){
  if($("select:[name='out_code'] ").val() == 0){
    alert('请选择出货原由');
    return false;
  }
  if($("select:[name='area_id'] ").val() == 0){
    alert('请选择地区');
    return false;
  }
  if($("#goods_list .td").length == 0){
    alert('请添加出货商品');
    return false;
  }
}
</script>


</html>
